package com.mall.controller;
import com.mall.pojo.Result;
import com.mall.service.loginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.Map;

@RestController
public class loginController {
    @Autowired
    private loginService loginService;
    @PostMapping("/login")
    public Result login(@RequestBody Map<String, String> request) {
        String account = request.get("account");
        String password = request.get("password");
        return loginService.getLoginByAccount(account, password);
    }
    @ExceptionHandler(ResponseStatusException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Result handleResponseStatusException(ResponseStatusException ex) {
        return Result.error(ex.getReason());
    }
}
